package com.system.Controller;

import com.common.Entity.Result;
import com.github.pagehelper.PageInfo;
import com.system.Entity.Announcement;
import com.system.Service.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/announcement")
public class AnnouncementController {
    @Autowired
    private AnnouncementService announcementService;

    @GetMapping("/getAnnouncementList")
    public Result getAnnouncementList(@RequestParam Integer pageNum,
                                      @RequestParam Integer pageSize,
                                      @RequestParam(required = false) String title,
                                      @RequestParam(required = false) String status) {
        PageInfo<Announcement> pageInfo = announcementService.getAnnouncementList(pageNum, pageSize, title,status);
        return Result.success(pageInfo);
    }

    @GetMapping("/getAnnouncements")
    public Result getAnnouncements() {
        return Result.success(announcementService.getAnnouncements());
    }

    @PostMapping("/addAnnouncement")
    public Result addAnnouncement(@RequestBody Announcement announcement) {
        announcementService.addAnnouncement(announcement);
        return Result.success();
    }

    @PutMapping("/updateAnnouncement")
    public Result updateAnnouncement(@RequestBody Announcement announcement) {
        announcementService.updateAnnouncement(announcement);
        return Result.success();
    }

    @PutMapping("/updateStatus")
    public Result deleteAnnouncement(@RequestBody Announcement announcement) {
        announcementService.updateStatus(announcement);
        return Result.success();
    }

    @DeleteMapping("/deleteAnnouncement/{announcementId}")
    public Result deleteAnnouncement(@PathVariable("announcementId") String announcementId) {
        announcementService.deleteAnnouncement(announcementId);
        return Result.success();
    }

}
